package com.ljfiction.book.Dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ljfiction.book.R;
import com.ljfiction.book.tools.ScreenUtils;

import java.util.Objects;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IsFirstPurseDialog {
    private Dialog mDialog;

    @SuppressLint("SetTextI18n")
    public IsFirstPurseDialog(Context context, String bookImage, String num, String bookName) {
        mDialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.isfirst_dialog, null);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.isfirstBookname.setText(bookName);
        viewHolder.isfirstnum.setText(num + "辣椒券");
        Glide.with(context).load(bookImage).override(ScreenUtils.getNum(context,78),ScreenUtils.getNum(context,104)).into(viewHolder.isFistBookiamge);
        //将布局设置给Dialog
        mDialog.setContentView(view);
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width = context.getResources().getDisplayMetrics().widthPixels;
        view.setLayoutParams(layoutParams);
        Objects.requireNonNull(mDialog.getWindow()).setGravity(Gravity.CENTER);
        mDialog.getWindow().setWindowAnimations(R.style.AnimBottom);
        mDialog.setCancelable(true);
    }

    public void show() {
        if (mDialog != null) {
            mDialog.show();
        }
    }

    static class ViewHolder {
        @BindView(R.id.isFist_bookiamge)
        ImageView isFistBookiamge;
        @BindView(R.id.isfirstnum)
        TextView isfirstnum;
        @BindView(R.id.isfirstBookname)
        TextView isfirstBookname;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
